function xscrack (action, varargin )

%XSCRACK Summary of this function goes here
%
%   XSCRACK(varagin) Detailed explanation goes here
%
%   Inputs:
%      hBlock       the block handle
%
%   Outputs:
%       --/--
%
%   Syntax:
%       xscrack(hBlock)
%
%   Example:
%       xscrack(gcb)
%
%   See also:
%
% 
%   Author(s): Xiaobiao Huang
%   Copyright 2013-2020 The Xiaobiao Studio.
%   $Revision: 1.0.0.0 $  $Date: 17-Sep-2013 21:23:54 $

switch action
    case 'blklist'
        hBlock = varargin{1};
        maskType = get_param(hBlock, 'MaskType');
        crackBlockTypeList = {...
                        'TL_Inport' ,...
                        'TL_Outport' ,...
                        'TL_Constant' ,...
                        'TL_Sum' ,...
                        'TL_Gain' ,...
                        'TL_Product' ,...
                        'TL_LogicalOperator' ,...
                        'TL_RelationalOperator' ,...
                        'TL_Fcn' ,...
                        'TL_Lookup1D' ,...
                        'TL_Lookup2D' ,...
                        'TL_LookupNDDirect' ,...
                        'TL_PreLookup' ,...
                        'TL_Interpolation_n-D' ,...
                        'TL_Assignment' ,...
                        'TL_Saturate' ,...
                        'TL_MinMax' ,...
                        'TL_Abs' ,...
                        'TL_Signum' ,...
                        'TL_RateLimiter' ,...
                        'TL_Relay' ,...
                        'TL_Trigonometry' ,...
                        'TL_Math' ,...
                        'TL_Sqrt' ,...
                        'TL_UnitDelay' ,...
                        'TL_DiscreteTransferFcn' ,...
                        'TL_DiscreteFilter' ,...
                        'TL_FIRFilter' ,...
                        'TL_DiscreteIntegrator' ,...
                        'TL_DiscreteStateSpace' ,...
                        'TL_DataStoreWrite' ,...
                        'TL_DataStoreMemory' ,...
                        'TL_DataStoreRead' ,...
                        'TL_CustomCode' ,...
                        'TL_Merge' ,...
                        'TL_Sink' ,...
                        'TL_BitClear' ,...
                        'TL_BitSet' ,...
                        'TL_BitwiseOperator' ,...
                        'TL_ExtractBits' ,...
                        'TL_ShiftArithmetic' ,...
                        'TL_BusInport' ,...
                        'TL_BusOutport' ,...
                        'TL_Rescaler' ,...
                        'TL_Switch' ,...
                        'TL_MultiPortSwitch' ,...
                        'TL_UnitDelayRE' ,...
                        'TL_Constant' ,...
                        'TL_MainDialog' ,...
                        'TL_AddFile' ,...
                        'TL_Function' ,...
                        'TL_Task' ,...
                        'TL_ISR' ,...
                        'TL_CriticalSection' ,...
                        'TL_Schedule' ,...
                        'TL_CounterAlarm' ,...
                        'TL_ReceiverComSpec' ,...
                        'TL_SenderComSpec' ,...
                        'TL_SWCReceiverPort' ,...
                        'TL_SWCSenderPort' ,...
                        'TL_Function' ,...
                        'TL_DLatch' ,...
                        'TL_DFlipFlop' ,...
                        'TL_SRFlipFlop' ,...
                        'TL_JKFlipFlop' ,...
                        'TL_PreProcessorIf' ,...
                        };

        if strmatch(maskType,crackBlockTypeList)
            tl_pref('set', 'blockLibMode', 0);
        end
    case 'crack'
        dlgdata = varargin{1};
        dlgfig  = varargin{2};
        % add a crack button in the figure panel
        closeBtnPos = get(dlgdata.SystemButtons.Close,'Position'); 
        btnDeltaWith = dlgdata.commonGeom.sysButtonDelta+dlgdata.commonGeom.sysButtonWidth;
        crackBtnPos =  closeBtnPos - [btnDeltaWith 0 0 0];
        uicontrol( ...
            'Parent',            dlgfig,... 
            'ToolTipString',     'crack targetLink calibration',... 
            'String',            'Crack',... 
            'Horizontalalign',   'center',... 
            'Visible',           'on',... 
            'Position',          crackBtnPos, ...
            'Callback',         {@(obj,env)crackdlg(dlgfig)} ), ...
        % end of add crack button
end

end % end of function  xscrack

function crackdlg ( dlgfig,env )

%CRACKDLG Summary of this function goes here
%
%   CRACKDLG(varagin) Detailed explanation goes here
%
%   Inputs:
%      dlgfig,env
%
%   Outputs:
%
%
%   Syntax:
%
%
%   Example:
%
%
%   See also:
%
% 
%   Author(s): Xiaobiao Huang
%   Copyright 2013-2020 The Xiaobiao Studio.
%   $Revision: 1.0.0.0 $  $Date: 20-Sep-2013 11:05:41 $

% switch to full-featured blockset mode
tl_pref('set', 'blockLibMode', 1);
dlgdata = get(dlgfig,'UserData');
currentPageNum = dlgdata.CurrentPageNum;
pageData = dlgdata.pageData{currentPageNum};
if isfield(pageData,'children') & ~isempty(pageData.children)
	uihandle = struct2cell(pageData.children);
	for iUI = 1 : length(uihandle)
		try
			set(uihandle{iUI},'Enable','on');
			try
				style = get(uihandle{iUI},'style');
				if any(strcmp(style,{'edit','popupmenu'}))
					set(uihandle{iUI},'backgroundColor','white')
				end
			catch exception
				disp(exception.message);
			end
		catch exception
			disp(exception.message);
			continue;
		end
	end
end

end % end of function  crackdlg
